package com.bill.common.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {
	 private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); 
	 public static int daysBetween(Date smdate,Date bdate) throws ParseException{
	        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");  
	        smdate=sdf.parse(sdf.format(smdate));  
	        bdate=sdf.parse(sdf.format(bdate));  
	        Calendar cal = Calendar.getInstance();    
	        cal.setTime(smdate);    
	        long time1 = cal.getTimeInMillis();                 
	        cal.setTime(bdate);    
	        long time2 = cal.getTimeInMillis();         
	        long between_days=(time2-time1)/(1000*3600*24);  
	       return Integer.parseInt(String.valueOf(between_days));           
	    } 
	 public static  Date getFirstDayInMonth(){
		 //获取当前月第一天：
	     Calendar c = Calendar.getInstance();
	     try {
			c.setTime(format.parse(format.format(new Date())));
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		 c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
//		 String first = format.format(c.getTime());
//	     System.out.println("===============first:"+first+c.getTime());
		 return c.getTime();
	    
	    
	     
	 }
	 public static  Date getLastDayInMonth(){
		//获取当前月最后一天
	     Calendar ca = Calendar.getInstance();   
	     try {
	    	 ca.setTime(format.parse(format.format(new Date())));
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	     ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH)); 
//	     String last = format.format(ca.getTime());
//	     System.out.println("===============last:"+last+ca.getTime()); 
	     return ca.getTime();
	 }
}
